package com.nys.conci.base.validador;


import com.nys.conci.base.validador.anotacion.Email;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 *
 * @author Adam M. Gamboa González
 */
public class EmailValidator implements ConstraintValidator<Email, String> {
    
    private final String regex="(^[0-9a-zA-Z_-]+(?:[._][0-9a-zA-Z_-]+)*)@([0-9a-zA-Z_-]+(?:[._-][0-9a-zA-Z_-]+)*\\.[0-9a-zA-Z_-]{2,3})$";
    
    @Override
    public void initialize(Email constraintAnnotation) {
    }
    
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if(value == null || value.trim().isEmpty()){
            return false;
        }
        return value.matches(regex);
    }
}
